﻿goog.provide('imc.cmd.ReloadSolicitudes');

imc.cmd.ReloadSolicitudes = function () {
    imc.cmd.Loader.show();
    var todas = 'false';
    var idStatus = 3;
    var idTipo = 0;
    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
    $('#subMenu').load('solicitudes.html #subMenuSolicitudes', function () { });
    $('#subMenu2').load('solicitudes.html #subMenu2', function () { });
    $('#contenedorIzquierda').load('solicitudes.html #menuIzquierdaTblSolicitud', function () {
        var z1 = new goog.ui.AnimatedZippy('tituloPorTipo', 'contenedorPorTipo', true);
        var z2 = new goog.ui.AnimatedZippy('tituloStatus', 'contenedorPorStatus', true);
        $.ajax({
            url: "Services/Auth.svc/RefreshCounters",
            type: "POST",
            dataType: "json",
            data: '{"unidRol": "' + idRol + '"}',
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                document.getElementById('todas-solicitudes-con').innerHTML = '(' + data.RefreshCountersResult["contTodasRol"] + ')';
                document.getElementById('altas-solicitudes-con').innerHTML = '(' + data.RefreshCountersResult["contAltasRol"] + ')';
                document.getElementById('modificaciones-solicitudes-con').innerHTML = '(' + data.RefreshCountersResult["contModifiRol"] + ')';
                document.getElementById('reemplazos-solicitudes-con').innerHTML = '(' + data.RefreshCountersResult["contReemplazoRol"] + ')';
                document.getElementById('atendidas-solicitudes-con').innerHTML = '(' + data.RefreshCountersResult["contAtentidasRol"] + ')';
                document.getElementById('aprobadas-solicitudes-con').innerHTML = '(' + data.RefreshCountersResult["contAprobadasRol"] + ')';
                document.getElementById('rechazadas-solicitudes-con').innerHTML = '(' + data.RefreshCountersResult["ContRechazadaRol"] + ')';
                document.getElementById('revision-solicitudes-con').innerHTML = '(' + data.RefreshCountersResult["ContEnProcesoRol"] + ')';
                document.getElementById('cancelada-solicitudes-con').innerHTML = '(' + data.RefreshCountersResult["ContCanceladaRol"] + ')';

                $("#todas-solicitudes").css({ color: "white", background: "#246DA6" });
                $("#altas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                $("#modificaciones-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                $("#reemplazos-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                $("#atendidas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                $("#aprobadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                $("#rechazadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                $("#revision-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                $("#cancelada-solicitudes").css({ color: "Black", background: "#EBEBEB" });

                $('#todas-solicitudes').click(function () {
                    //h.setToken("Solicitudes/todas");
                    var todas = 'false';
                    var idStatus = 3;
                    var idTipo = 0;
                    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
                    $("#todas-solicitudes").css({ color: "white", background: "#246DA6" });
                    $("#altas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#modificaciones-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#reemplazos-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#atendidas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#aprobadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#rechazadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#revision-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#cancelada-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                });
                $('#altas-solicitudes').click(function () {
                    //h.setToken("Solicitudes/altas");
                    var todas = 'false';
                    var idStatus = 3;
                    var idTipo = 1;
                    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
                    $("#todas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#altas-solicitudes").css({ color: "white", background: "#246DA6" });
                    $("#modificaciones-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#reemplazos-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#atendidas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#aprobadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#rechazadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#revision-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#cancelada-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                });
                $('#modificaciones-solicitudes').click(function () {
                    //h.setToken("Solicitudes/modificaciones");
                    var todas = 'false';
                    var idStatus = 3;
                    var idTipo = 2;
                    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
                    $("#todas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#altas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#modificaciones-solicitudes").css({ color: "white", background: "#246DA6" });
                    $("#reemplazos-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#atendidas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#aprobadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#rechazadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#revision-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#cancelada-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                });
                $('#reemplazos-solicitudes').click(function () {
                    //h.setToken("Solicitudes/reemplazos");
                    var todas = 'false';
                    var idStatus = 3;
                    var idTipo = 3;
                    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
                    $("#todas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#altas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#modificaciones-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#reemplazos-solicitudes").css({ color: "white", background: "#246DA6" });
                    $("#atendidas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#aprobadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#rechazadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#revision-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#cancelada-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                });
                $('#atendidas-solicitudes').click(function () {
                    //h.setToken("Solicitudes/todas");
                    var todas = 'true';
                    var idStatus = 8;
                    var idTipo = 0;
                    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
                    $("#todas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#altas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#modificaciones-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#reemplazos-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#atendidas-solicitudes").css({ color: "white", background: "#246DA6" });
                    $("#aprobadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#rechazadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#revision-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#cancelada-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                });
                $('#revision-solicitudes').click(function () {
                    //h.setToken("Solicitudes/aprobadas");
                    var todas = 'true';
                    var idStatus = 3;
                    var idTipo = 0;
                    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
                    $("#todas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#altas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#modificaciones-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#reemplazos-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#atendidas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#aprobadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#rechazadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#revision-solicitudes").css({ color: "white", background: "#246DA6" });
                    $("#cancelada-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                });
                $('#aprobadas-solicitudes').click(function () {
                    //h.setToken("Solicitudes/aprobadas");
                    var todas = 'false';
                    var idStatus = 4;
                    var idTipo = 0;
                    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
                    $("#todas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#altas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#modificaciones-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#reemplazos-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#atendidas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#aprobadas-solicitudes").css({ color: "white", background: "#246DA6" });
                    $("#rechazadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#revision-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#cancelada-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                });
                $('#rechazadas-solicitudes').click(function () {
                    //h.setToken("Solicitudes/aprobadas");
                    var todas = 'false';
                    var idStatus = 6;
                    var idTipo = 0;
                    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
                    $("#todas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#altas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#modificaciones-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#reemplazos-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#atendidas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#aprobadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#rechazadas-solicitudes").css({ color: "white", background: "#246DA6" });
                    $("#revision-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#cancelada-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                });
                $('#cancelada-solicitudes').click(function () {
                    //h.setToken("Solicitudes/aprobadas");
                    var todas = 'true';
                    var idStatus = 5;
                    var idTipo = 0;
                    imc.cmd.GridSolicitudes.dataTableSolicitudes(todas, idStatus, idTipo, idRol);
                    $("#todas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#altas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#modificaciones-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#reemplazos-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#atendidas-solicitudes").css({ color: "Black", background: "#BDBDBD" });
                    $("#aprobadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#rechazadas-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#revision-solicitudes").css({ color: "Black", background: "#EBEBEB" });
                    $("#cancelada-solicitudes").css({ color: "white", background: "#246DA6" });
                });
            },
            error: function () {
                window.location.href = "paginaDeError.html";
                console.log('Error al cargar refresh counters');
            }
        });
    });
}

